﻿/*
 * 描 述：导入配置管理
 */
var acceptClick;
var bootstrap = function ($, learun) {
    "use strict";
    var currentData = top.layer_Form.currentData;
    var dictCode = '';
    var datasourceId = '';
    var page = {
        init: function () {
            page.bind();
            page.initData();
        },
        bind: function () {
            // 数据来源设置
            $('#dictCode').lrselect({
                allowSearch: true,
                maxHeight: 130,
                url: config.base_server() + 'dicts/tree?access_token=' + config.getToken().access_token,
                type: 'tree',
                select: function (item) {
                    if (!!item && item.id != -1) {
                        dictCode = item.value;
                        datasourceId = item.id;
                    }
                    else {
                        dictCode = '';
                        datasourceId = '';
                    }
                }
            });

            $('#datasourceId').lrformselect({
                placeholder: '请选择数据源项',
                layerUrl: config.webportal_server + 'pages/database/source/selectForm.html?access_token=' + config.getToken().access_token,
                layerUrlH: 500,
                layerUrlW: 800,
                dataUrl: config.base_server() + 'dbSources/getName?access_token=' + config.getToken().access_token,
            });

            $('#relationType').lrselect({
                data: [{"id": 0, "text": "无关联"}, {"id": 1, "text": "GUID"}, {"id": 2, "text": "数据字典"}, {
                    "id": 3,
                    "text": "数据来源"
                }, {"id": 4, "text": "固定数据"}, {"id": 5, "text": "登录者ID"}, {"id": 6, "text": "登录者名字"}, {
                    "id": 7,
                    "text": "导入时间"
                }],
                placeholder: false,
                maxHeight: 190,
                select: function (item) {
                    $('#dictCode').parent().hide();
                    $('#datasourceId').parent().hide();
                    $('#value').parent().hide();
                    if (item.id == 2) {
                        $('#dictCode').parent().show();
                    }
                    else if (item.id == 3) {
                        $('#datasourceId').parent().show();
                    }
                    else if (item.id == 4) {
                        $('#value').parent().show();
                    }
                }
            });
        },
        initData: function () {
            if (!!currentData) {
                if (currentData.F_RelationType == 2) {
                    dictCode = currentData.dictCode;
                    datasourceId = currentData.datasourceId;
                    $('#F_DataItemCode').lrselectSet(datasourceId);
                    currentData.datasourceId = '';
                    currentData.dictCode = '';
                    $('#form').lrSetFormData(currentData);
                    currentData.dictCode = dictCode;
                    currentData.datasourceId = datasourceId;
                }
                else {
                    $('#form').lrSetFormData(currentData);
                }
            }
        }
    };
    // 保存数据
    acceptClick = function (callBack) {
        var formData = $('#form').lrGetFormData();
        if (!!callBack) {
            if (formData.relationType == 2) {
                formData.datasourceId = datasourceId;
                formData.dictCode = dictCode;
            }
            callBack(formData);
        }
        return true;
    };
    page.init();
}